******************************************************
* Program to generate artificial data for estimation
******************************************************

clear all
set processors 1
set type double
set seed     123456789
set sortseed 123456789
set more off

global path= "D:\Elena\pastorino_2023_careers_in_firms\" // modify as necessary
set obs 1430                                             // sets the same number of observations as in the original data

gen v1=1

forvalues i=2(1)36 {
	gen v`i'=. 
		
}


forvalues i=2(3)32 {
	replace v`i'=runiform(33846,64014) // draw salaries uniformly from the range p10-p90 of the original pooled salary data
	
}


forvalues i=3(3)33 {
	gen e`i'=runiform(0,1) 
	
}

forvalues i=3(3)33 { // draw high and low performace ratings
	replace v`i'=0 if e`i'<0.5   
	replace v`i'=1 if e`i'>=0.5
}

drop e* 

forvalues i=2/11 {
	gen e`i'=runiform(0,1)
}

local j=4  // draw job level paths with one-level promotions
forvalues i=2/11 {
	local q=`j'-3
	replace v`j'= v`q'+1 if v`q'<3 & e`i'>=0.5
	replace v`j'= v`q' if v`q'==3 
	replace v`j'= v`q' if e`i'<0.5
	local j=`j'+3
}

gen die=rnbinomial(1,0.5)    //draw date of first ``success'' (separation)

local l=4
local s=5
local p=6

forvalues i=0(1)9 {
	replace v`l'=-2 if die<=`i'
	replace v`s'=-2 if die<=`i'
	replace v`p'=-2 if die<=`i'
	
	local l=`l'+3
    local s=`s'+3
    local p=`p'+3
	
}


drop die

  
replace v34=int(runiform(16,23)) // draw demographics from the range of initial demographics
replace v35=int(runiform(30,40))
replace v36=int(runiform(70,79))



drop e* 

export delimited using "$path\fortran_sample_artificial.txt", delimiter(tab) novarnames replace
